154
Beginner’s Guide to Code Algorithms
154
STEP 5 continued
With thisWb.Worksheets(“States”).Sort
.SetRange Range(“E1:G52”)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
STEP 6
Draw the first chart (all states’ cumulative COVID count).
‘ First overall graph
thisWsGraphs.Activate
NameOfOverallChart = “All states cumulative covid count”
ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Select
ActiveChart.SetSourceData Source:=Range(“States!$E$1:$F$52”)
ActiveChart.ChartType = xlBarClustered
‘ActiveChart.ChartType = xlColumnClustered
ActiveChart.Parent.Name = NameOfOverallChart
ActiveChart.ChartTitle.Text = NameOfOverallChart
ActiveSheet.Shapes(NameOfOverallChart).Left = 50
ActiveSheet.Shapes(NameOfOverallChart).Top = 1
ActiveSheet.Shapes(NameOfOverallChart).ScaleWidth 0.5, msoFalse,
msoScaleFromTopLeft
ActiveSheet.Shapes(NameOfOverallChart).ScaleHeight 1, msoFalse,
msoScaleFromBottomRight
ActiveSheet.ChartObjects(NameOfOverallChart).Chart.HasLegend = True
ActiveSheet.ChartObjects(NameOfOverallChart).Chart.Legend.
Position = xlBottom
ActiveSheet.Shapes(NameOfOverallChart).Fill.ForeColor.
ObjectThemeColor = msoThemeColorAccent4
ActiveChart.Axes(xlValue).MajorGridlines.Select
STEP 7
Draw the first state in the second chart.
TopHowMany = UserForm1.TextBox1.Value
If TopHowMany = ““ Then
TopHowMany = 5
End If
Dim SpecificState() As String
SpecificState = Split(TopHowMany)
SpecificStateColumn = ““
For m = 1 To NumberOfStates
a = InStr(1, SpecificState(0), thisWb.Sheets(“States”).Cells(1 + m, 1), 1)
If a > 0 Then
SpecificState(0) = Mid(SpecificState(0), 1, 2)
SpecificStateColumn = m
End If
Next
ErrorInput = “N”
If SpecificStateColumn = ““ And (TopHowMany < 0 Or TopHowMany > 52) Then